using UnityEngine;

public class EnemyHealth : MonoBehaviour
{
    [SerializeField] private float maxHealth = 10f;
    [SerializeField] private int experienceDrop = 5; // GDD中小骷髅掉落5点经验
    [SerializeField] private GameObject experienceGemPrefab; // 引用经验宝石预制体

    private float currentHealth;

    void Awake()
    {
        currentHealth = maxHealth;
    }

    public void TakeDamage(float damage)
    {
        currentHealth -= damage;
        if (currentHealth <= 0)
        {
            Die();
        }
    }

    private void Die()
    {
        // 掉落经验
        if (experienceGemPrefab != null)
        {
            GameObject gem = Instantiate(experienceGemPrefab, transform.position, Quaternion.identity);
            gem.GetComponent<ExperienceGem>().experienceValue = this.experienceDrop;
        }

        Debug.Log(gameObject.name + " 被击败了!");
        Destroy(gameObject);
    }
}